package cn.anc.aonicardv.module.ui.recorder;

import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.OnClick;
import cn.anc.aonicardv.Constant;
import cn.anc.aonicardv.R;
import cn.anc.aonicardv.R2;
import cn.anc.aonicardv.module.ui.base.BaseActivity;
import cn.anc.aonicardv.widget.EVMeterView;
import cn.anc.httpcontrolutil.CarControl;
import cn.anc.httpcontrolutil.CarControlSettings;

public class EVActivity extends BaseActivity implements EVMeterView.OnSelectListener {

    @BindView(R.id.ev_setting)
    EVMeterView evMeterView;
    @BindView(R.id.tv_title)
    TextView titleTv;
    CarControlSettings.SettingItem currentSettingItem;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_ev);
        super.onCreate(savedInstanceState);
    }

    @Override
    public void initVariable() {
        String key = getIntent().getStringExtra(Constant.IntentKeyParam.SETTING_KEY);
        currentSettingItem = CarControlSettings.getSettingItem(key);
        String[] values = currentSettingItem.settingItemOptions.toArray(new String[]{});
        evMeterView.setValues(values, currentSettingItem.settingItemValue);
    }

    @Override
    public void setListener() {
        evMeterView.setOnSelectListener(this);
    }

    @Override
    public void initData() {
        titleTv.setText(R.string.car_setting_name_ev);
    }

    @Override
    public void onSelect(int position) {
        currentSettingItem.settingItemValue = currentSettingItem.settingItemOptions.get(position);
        CarControl.doSetSettingItemValue(currentSettingItem.settingItemKey, currentSettingItem.settingItemValue, new CarControl.OnCarControlCallback() {
            @Override
            public void OnCommandCallback(int code, CarControl.CommandResponseInfo info) {
            }
        });
    }

    @OnClick(R2.id.tv_back)
    public void back() {
        finish();
    }
}
